//
//  TTCommitOrderHeaderView.m
//  TaoTuo
//
//  Created by 周晨晔 on 2019/9/23.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTCommitOrderHeaderView.h"
#import "TTAddressModel.h"
#import "TTChargeStandardView.h"
#import <TYAlertController.h>
#import <UIView+TYAlertView.h>

static NSInteger btnBaseTag = 20000;

@interface TTCommitOrderHeaderView ()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIButton *takeGoodsBtn;   // 收货地址
@property (nonatomic, strong) UIView *btnsBGView;
//@property (nonatomic, strong) UIButton *mailBtn;    // 邮寄
//@property (nonatomic, strong) UIButton *extractBtn; // 自提
@property (nonatomic, strong) UIImageView *addressImageView;
@property (nonatomic, strong) UILabel *mailManLabel;    // 收货人
@property (nonatomic, strong) UILabel *addressLabel;    // 收货地址
@property (nonatomic, strong) UIImageView *arrowImageView;

@property (nonatomic, strong) UIView *lineView1;
@property (nonatomic, strong) UIView *lineView2;
@property (nonatomic, strong) UIView *lineView3;
@property (nonatomic, strong) UIView *lineView4;

@property (nonatomic, strong) UIView *lineView5;

@property (nonatomic, strong) UIButton *chargeBtn;   // 收费标准

@property (nonatomic, strong) TTAddressModel *mailModel;    // 邮寄model
@property (nonatomic, strong) TTAddressModel *extractModel; // 自提model
@property (nonatomic, assign) BOOL isNeedInset; // 是否要镶嵌
@property (nonatomic, strong) UIButton *xqInfoBtn;  ///镶嵌说明
/// 数据
@property (nonatomic, strong) NSDictionary *dataDic;

@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) NSMutableArray *btnsArray;
/// 从回收来的
@property (nonatomic, assign) BOOL isFromRecycling;

@end

@implementation TTCommitOrderHeaderView

+ (instancetype)headerViewWithAddress:(TTAddressModel *)model
{
    return [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100) addressModel:model isNeedInset:YES isFromRecycling:NO];
}

+ (instancetype)headerViewWithAddress:(TTAddressModel *)model isNeedInset:(BOOL)isNeedInset
{
    return [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100) addressModel:model isNeedInset:isNeedInset isFromRecycling:NO];
}

+ (instancetype)headerViewIsFromRecyclingWithAddress:(TTAddressModel *)model
{
    TTCommitOrderHeaderView *view = [[self alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100) addressModel:model isNeedInset:NO isFromRecycling:YES];
    return view;
}

- (instancetype)initWithFrame:(CGRect)frame addressModel:(TTAddressModel *)model isNeedInset:(BOOL)isNeedInset isFromRecycling:(BOOL)isFromRecycling
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.dataDic = @{
            @"1" : @"    请选择您的收货地址",
            @"2" : @"    请选择您的提货地址",
            @"3" : @"    请选择工厂地址",
        };
        self.btnsArray = [NSMutableArray array];
        self.isNeedInset = isNeedInset;
        self.isFromRecycling = isFromRecycling;
        
        [self setupSubviews];
        
        _model = model;
        
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}

- (void)setModel:(TTAddressModel *)model receiveType:(ReceiveType)receiveType
{
    self.receiveType = receiveType;
    
    if (receiveType == ReceiveTypeWithSendFactory) {
        self.phoneTF.hidden = YES;
        self.remarkTF.hidden = YES;
        self.khmTF.hidden = NO;
        self.contactTF.hidden = NO;
        self.factoryTF.hidden = NO;
    } else {
        self.phoneTF.hidden = NO;
        self.remarkTF.hidden = NO;
        self.khmTF.hidden = YES;
        self.contactTF.hidden = YES;
        self.factoryTF.hidden = YES;
        /// 回收页面隐藏手机号
        self.phoneTF.hidden = self.isFromRecycling;
    }
    
    if (model == nil) {
        self.mailManLabel.text = @" ";
        self.addressLabel.text = @" ";
        NSString *key = [NSString stringWithFormat:@"%ld", receiveType];
        [self.tapBtn setTitle:self.dataDic[key] forState:UIControlStateNormal];
        
    } else {
        
        _model = model;
        
        if (receiveType == ReceiveTypeWithMail) {
            
            self.mailModel = model;
            self.mailManLabel.text = [NSString stringWithFormat:@"收货人：%@    %@", model.ReceiverName, model.ReceiverMobile];
            self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@", model.Province, model.City, model.Area, model.Address];
            
        } else if (receiveType == ReceiveTypeWithSelfTake) {
            
            self.extractModel = model;
            self.mailManLabel.text = [NSString stringWithFormat:@"取货地址：%@%@%@%@", model.Province, model.City, model.Area, model.Address];
            self.addressLabel.text = [NSString stringWithFormat:@"客服电话：%@", model.ReceiverMobile];
            
        } else if (receiveType == ReceiveTypeWithSendFactory) {
            
            self.factoryModel = model;
            
            self.mailManLabel.text = [NSString stringWithFormat:@"%@", model.ReceiverName];
            self.addressLabel.text = [NSString stringWithFormat:@"工厂地址：%@%@%@%@", model.Province, model.City, model.Area, model.Address];
            
        }
        
        [self.tapBtn setTitle:@"" forState:UIControlStateNormal];
    }
    
    self.factoryTF.hidden = receiveType != ReceiveTypeWithSendFactory;
    self.lineView5.hidden = receiveType != ReceiveTypeWithSendFactory;
    
    [self setNeedsLayout];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshHeaderViewNotify_key" object:nil];
    
}

//- (void)setModel:(TTAddressModel *)model isMail:(BOOL)isMail
//{
//    _isMail = isMail;
//
//    if (model != nil) {
//
//        _model = model;
//
//        if (isMail) {
//            // 邮寄
//            self.mailModel = model;
//            self.mailManLabel.text = [NSString stringWithFormat:@"收货人：%@    %@", model.ReceiverName, model.ReceiverMobile];
//            self.addressLabel.text = [NSString stringWithFormat:@"%@%@%@%@", model.Province, model.City, model.Area, model.Address];
//        } else {
//            // 自提
//            self.extractModel = model;
//            self.mailManLabel.text = [NSString stringWithFormat:@"取货地址：%@%@%@%@", model.Province, model.City, model.Area, model.Address];
//            self.addressLabel.text = [NSString stringWithFormat:@"客服电话：%@", model.ReceiverMobile];
//        }
//
//        [self setModelIsMail:isMail];
//
//        [self.tapBtn setTitle:@"" forState:UIControlStateNormal];
//
//    } else {
//        self.mailManLabel.text = @" ";
//        self.addressLabel.text = @" ";
//        NSString *str = isMail ? @"    请选择您的收货地址" : @"    请选择您的提货地址";
//        [self.tapBtn setTitle:str forState:UIControlStateNormal];
//    }
//
//
//    [self setNeedsLayout];
//
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshHeaderViewNotify_key" object:nil];
//}

- (void)buttonClick:(UIButton *)sender
{
    if (sender.selected) {
        return;
    }
    self.selectBtn.selected = NO;
    sender.selected = YES;
    self.selectBtn = sender;
    
    self.receiveType = sender.tag - btnBaseTag;
    
    if (self.receiveType == ReceiveTypeWithSelfTake) {
        if (self.extractModel == nil) {
            NSDictionary *dic = @{
                @"title": @"南非甄钻(杭州店)",
                @"Address":@"建设三路国际珠宝城A103",
                @"ReceiverName":@"南非甄钻(杭州店)",
                @"ReceiverMobile":@"0571-82573193",
                @"Province":@"浙江省",
                @"City":@"杭州市",
                @"Area":@"萧山区",
            };
            self.extractModel = [TTAddressModel modelWithJSON:dic];
        }
        
        [self setModel:self.extractModel receiveType:_receiveType];
        
    } else if (self.receiveType == ReceiveTypeWithMail){
        
        [self setModel:self.mailModel receiveType:_receiveType];
        
    } else if (self.receiveType == ReceiveTypeWithSendFactory) {
        
        [self setModel:self.factoryModel receiveType:_receiveType];
        
    }
    
    
}

//// 自提按钮
//- (void)extractButtonClick:(UIButton *)sender
//{
//    if (sender.selected) {
//        return;
//    }
//    [self setModelIsMail:NO];
//    self.mailBtn.selected = sender.selected;
//    sender.selected = !sender.selected;
//    //设置默认值
//    if (self.extractModel == nil) {
//        NSDictionary *dic = @{
//            @"title": @"南非甄钻(杭州店)",
//            @"Address":@"建设三路国际珠宝城A103",
//            @"ReceiverName":@"南非甄钻(杭州店)",
//            @"ReceiverMobile":@"0571-82573193",
//            @"Province":@"浙江省",
//            @"City":@"杭州市",
//            @"Area":@"萧山区",
//        };
//        self.extractModel = [TTAddressModel modelWithJSON:dic];
//    }
//
//    [self setModel:self.extractModel isMail:NO];
//}
//
//// 邮寄按钮
//- (void)mailButtonClick:(UIButton *)sender
//{
//    if (sender.selected) {
//        return;
//    }
//    [self setModelIsMail:YES];
//    self.extractBtn.selected = sender.selected;
//    sender.selected = !sender.selected;
//
//    [self setModel:self.mailModel isMail:YES];
//
//}

//- (void)setModelIsMail:(BOOL)isMail
//{
//    self.model.isMail = isMail;
//    self.mailModel.isMail = isMail;
//    self.extractModel.isMail = isMail;
//    _isMail = isMail;
//}


// 选取地址
- (void)chooseAddressAction
{
    if ([self.delegate respondsToSelector:@selector(clickChooseAddressBtnWithHeaderView:)]) {
        [self.delegate clickChooseAddressBtnWithHeaderView:self];
    }
}

// 需镶嵌
- (void)insetBtnClick:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(clickInsetButton:headerView:)]) {
        [self.delegate clickInsetButton:sender headerView:self];
    }
}

// 收费标准
- (void)chargeBtnClick
{
    TTChargeStandardView *standardView = [TTChargeStandardView createViewFromNib];
    standardView.frame = CGRectMake(0, 0, SCREEN_WIDTH - 70, 220);
    standardView.layer.cornerRadius = 10;
    TYAlertController *alertVC = [TYAlertController alertControllerWithAlertView:standardView preferredStyle:TYAlertControllerStyleAlert];
    alertVC.backgoundTapDismissEnable = YES;
    [self.viewController presentViewController:alertVC animated:YES completion:nil];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(38);
    }];
    
    [self.takeGoodsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.equalTo(self.topView);
    }];
    
    [self.btnsBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.takeGoodsBtn.mas_right).mas_offset(15);
        make.top.bottom.equalTo(self.topView);
        make.width.mas_equalTo(180);
    }];
    
    [self.btnsArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:0 tailSpacing:20];
    [self.btnsArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.equalTo(self.topView);
    }];
    
//    [self.mailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.takeGoodsBtn.mas_right).mas_offset(15);
//        make.centerY.height.equalTo(self.topView);
//    }];
//
//    [self.extractBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mailBtn.mas_right).mas_offset(15);
//        make.centerY.height.equalTo(self.topView);
//    }];
    
//    [self.addressImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.topView.mas_bottom).mas_offset(20);
//        make.left.mas_equalTo(10);
//        make.width.height.mas_equalTo(25);
//    }];
    
    [self.mailManLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom).mas_offset(15);
//        make.left.equalTo(self.addressImageView.mas_right).mas_offset(10);
        make.left.mas_equalTo(45);
        make.right.equalTo(self).mas_offset(-30);
    }];
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mailManLabel.mas_bottom).mas_offset(3);
        make.left.right.equalTo(self.mailManLabel);
    }];
    
    
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.equalTo(self.addressLabel.mas_bottom).mas_offset(10);
        make.right.equalTo(self).mas_offset(-10);
        make.height.mas_equalTo(1);
    }];
    
    [self.tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.equalTo(self.addressImageView.mas_right);
        make.right.equalTo(self);
        make.bottom.equalTo(self.lineView1);
    }];
    
    [self.addressImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tapBtn);
        make.left.mas_equalTo(10);
        make.width.height.mas_equalTo(25);
    }];
    
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).mas_offset(-10);
        make.centerY.equalTo(self.addressImageView);
    }];
    
    CGFloat phoneH = self.isFromRecycling ? 0 : 45;
    [self.phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.lineView1);
        make.top.equalTo(self.lineView1.mas_bottom);
        make.height.mas_equalTo(phoneH);
    }];
    
    [self.khmTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.phoneTF);
    }];
    
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.lineView1);
        make.top.equalTo(self.phoneTF.mas_bottom);
    }];
    
    [self.remarkTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.phoneTF);
        make.height.mas_equalTo(45);
        make.top.equalTo(self.lineView2.mas_bottom);
    }];
    
    [self.contactTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.remarkTF);
    }];
    
    [self.lineView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.lineView1);
        make.top.equalTo(self.remarkTF.mas_bottom);
    }];
    
    [self.factoryTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.phoneTF);
        make.top.equalTo(self.lineView5.mas_bottom);
    }];
    
    MASViewAttribute *lineView3Attr = self.receiveType == ReceiveTypeWithSendFactory ? self.factoryTF.mas_bottom : self.remarkTF.mas_bottom;
    [self.lineView3 mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(lineView3Attr);
        make.height.mas_equalTo(10);
    }];
    
    [self.insetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView3.mas_bottom).mas_offset(15);
        make.left.equalTo(self);
    }];
    
    [self.chargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.insetBtn);
        make.left.equalTo(self.insetBtn.mas_right).mas_offset(8);
    }];
    
    [self.xqInfoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.insetBtn);
        make.left.equalTo(self.chargeBtn.mas_right).mas_offset(3);
    }];
    
    [self.lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(self.lineView1);
        make.top.equalTo(self.insetBtn.mas_bottom).mas_offset(10);
    }];
    
    [self layoutIfNeeded];
    
    self.height = self.isNeedInset ? self.lineView4.bottom + 5 : self.lineView3.bottom;
    
}

- (void)setupSubviews
{
    _topView = [[UIView alloc] init];
    _topView.backgroundColor = kSeparatorColor;
    [self addSubview:_topView];
    
    _takeGoodsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_takeGoodsBtn setTitle:@" 收货方式:" forState:UIControlStateNormal];
    [_takeGoodsBtn setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
    _takeGoodsBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [_takeGoodsBtn setImage:[UIImage imageNamed:@"songhuo"] forState:UIControlStateNormal];
    [_topView addSubview:_takeGoodsBtn];
    
    _btnsBGView = [[UIView alloc] init];
    [_topView addSubview:_btnsBGView];
    
//    NSArray *btnTitles = @[@" 邮寄", @" 自提", @" 送厂"];
//    if (self.isFromRecycling) {
//        btnTitles = @[@" 邮寄", @" 自提"];
//    }
    NSArray *btnTitles = @[@" 邮寄", @" 自提"];
    for (int i = 0; i < btnTitles.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.tag = btnBaseTag + i + 1;
        [btn setTitle:btnTitles[i] forState:UIControlStateNormal];
        [btn setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [btn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btnsBGView addSubview:btn];
        [self.btnsArray addObject:btn];
        
        if (i == 0) {
            btn.selected = YES;
            self.selectBtn = btn;
        }
    }
    
//    _mailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_mailBtn setTitle:@" 邮寄" forState:UIControlStateNormal];
//    [_mailBtn setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
//    _mailBtn.titleLabel.font = [UIFont systemFontOfSize:12];
//    [_mailBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
//    [_mailBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
//    [_mailBtn addTarget:self action:@selector(mailButtonClick:) forControlEvents:UIControlEventTouchUpInside];
//    _mailBtn.selected = YES;
//    [_topView addSubview:_mailBtn];
//
//    _extractBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_extractBtn setTitle:@" 自提" forState:UIControlStateNormal];
//    [_extractBtn setTitleColor:UIColorHex(666666) forState:UIControlStateNormal];
//    _extractBtn.titleLabel.font = [UIFont systemFontOfSize:12];
//    [_extractBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
//    [_extractBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
//    [_extractBtn addTarget:self action:@selector(extractButtonClick:) forControlEvents:UIControlEventTouchUpInside];
//    [_topView addSubview:_extractBtn];
    
    _addressImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"orderaddress"]];
    [self addSubview:_addressImageView];
    
    _mailManLabel = [UILabel labelWithTitle:@"" color:UIColorHex(282828) fontSize:15];
    _mailManLabel.numberOfLines = 0;
    [self addSubview:_mailManLabel];
    
    _addressLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:12];
    _addressLabel.numberOfLines = 0;
    [self addSubview:_addressLabel];
    
    _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btn_right_arrow"]];
    [self addSubview:_arrowImageView];
    
    _tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _tapBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _tapBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_tapBtn setTitleColor:UIColorHex(282828) forState:UIControlStateNormal];
    [_tapBtn addTarget:self action:@selector(chooseAddressAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_tapBtn];
    
    _lineView1 = [[UIView alloc] init];
    _lineView1.backgroundColor = kSeparatorColor;
    [self addSubview:_lineView1];
    
    _phoneTF = [[UITextField alloc] init];
    _phoneTF.placeholder = @"下单人手机号，方便配货中沟通";
    _phoneTF.font = [UIFont systemFontOfSize:13];
    _phoneTF.textColor = UIColorHex(282828);
    UILabel *phoneLabel = [UILabel labelWithTitle:@"手机号：" color:UIColorHex(282828) fontSize:15];
    [phoneLabel sizeToFit];
    _phoneTF.leftViewMode = UITextFieldViewModeAlways;
    _phoneTF.leftView = phoneLabel;
    [self addSubview:_phoneTF];
    
    _lineView2 = [[UIView alloc] init];
    _lineView2.backgroundColor = kSeparatorColor;
    [self addSubview:_lineView2];
    
    _remarkTF = [[UITextField alloc] init];
    _remarkTF.placeholder = @"给商家留言，对本次订单说明";
    _remarkTF.font = [UIFont systemFontOfSize:13];
    _remarkTF.textColor = UIColorHex(282828);
    UILabel *remarkLabel = [UILabel labelWithTitle:@"备注：" color:UIColorHex(282828) fontSize:15];
    [remarkLabel sizeToFit];
    _remarkTF.leftViewMode = UITextFieldViewModeAlways;
    _remarkTF.leftView = remarkLabel;
    [self addSubview:_remarkTF];
    
    _lineView5 = [[UIView alloc] init];
    _lineView5.backgroundColor = kSeparatorColor;
    _lineView5.hidden = YES;
    [self addSubview:_lineView5];
    
    _khmTF = [[UITextField alloc] init];
    _khmTF.placeholder = @"工厂开户名";
    _khmTF.font = [UIFont systemFontOfSize:13];
    _khmTF.textColor = UIColorHex(282828);
    UILabel *khmLabel = [UILabel labelWithTitle:@"开户名：" color:UIColorHex(282828) fontSize:15];
    [khmLabel sizeToFit];
    _khmTF.leftViewMode = UITextFieldViewModeAlways;
    _khmTF.leftView = khmLabel;
    _khmTF.hidden = YES;
    [self addSubview:_khmTF];
    
    _contactTF = [[UITextField alloc] init];
    _contactTF.placeholder = @"工厂联系人姓名";
    _contactTF.font = [UIFont systemFontOfSize:13];
    _contactTF.textColor = UIColorHex(282828);
    UILabel *contactLabel = [UILabel labelWithTitle:@"联系人：" color:UIColorHex(282828) fontSize:15];
    [contactLabel sizeToFit];
    _contactTF.leftViewMode = UITextFieldViewModeAlways;
    _contactTF.leftView = contactLabel;
    _contactTF.hidden = YES;
    [self addSubview:_contactTF];
    
    _factoryTF = [[UITextField alloc] init];
    _factoryTF.placeholder = @"下单人手机号，方便配货中沟通";
    _factoryTF.keyboardType = UIKeyboardTypePhonePad;
    _factoryTF.font = [UIFont systemFontOfSize:13];
    _factoryTF.textColor = UIColorHex(282828);
    UILabel *factoryLabel = [UILabel labelWithTitle:@"手机号：" color:UIColorHex(282828) fontSize:15];
    [factoryLabel sizeToFit];
    _factoryTF.leftViewMode = UITextFieldViewModeAlways;
    _factoryTF.leftView = factoryLabel;
    _factoryTF.hidden = YES;
    [self addSubview:_factoryTF];
    
    
    
    
    _lineView3 = [[UIView alloc] init];
    _lineView3.backgroundColor = kSeparatorColor;
    [self addSubview:_lineView3];
    
    if (self.isNeedInset) {
        // 要镶嵌的
        _insetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_insetBtn setTitle:@" 需镶嵌" forState:UIControlStateNormal];
        [_insetBtn setTitleColor:kMainColor forState:UIControlStateNormal];
        _insetBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_insetBtn setImage:[UIImage imageNamed:@"address_unsel"] forState:UIControlStateNormal];
        [_insetBtn setImage:[UIImage imageNamed:@"address_sel"] forState:UIControlStateSelected];
        [_insetBtn addTarget:self action:@selector(insetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _insetBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [self addSubview:_insetBtn];
        
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"收费标准" attributes:@{NSUnderlineStyleAttributeName : @1, NSUnderlineColorAttributeName : kMainColor, NSForegroundColorAttributeName : kMainColor}];
        _chargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_chargeBtn setAttributedTitle:attr forState:UIControlStateNormal];
        _chargeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_chargeBtn addTarget:self action:@selector(chargeBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_chargeBtn];
        
        _lineView4 = [[UIView alloc] init];
        _lineView4.backgroundColor = kSeparatorColor;
        [self addSubview:_lineView4];
        
        _xqInfoBtn = [UIButton createButtonWithTitle:@"暂不支持镶口10分及其以下的戒托" titleColor:UIColorHex(FF1F1F) titleFont:[UIFont systemFontOfSize:10] backgroundColor:nil target:nil action:nil];
        [_xqInfoBtn setImage:[UIImage imageNamed:@"hintgantanhao"] forState:UIControlStateNormal];
        [self addSubview:_xqInfoBtn];
    }
    
    
}

@end
